efform_onload = function ()
{	
	hideAndShowSubButtons(false);
	efgrid.submitInqu( "ef_grid_r", "ZM","ZMCG40","query");
	var info = new EiInfo();
	$('#ef_region_detail').hide();//隐藏从表区域
	$('#ef_region_inqu1').hide();//隐藏从表明细区域
	EiCommunicator.send("ZMCG4001", "query", info, ajax_callback1);
//	$('#inqu_status1-0-fdCreateDepartmentId').val($('#fdCreateDepartmentId').val());
//	$('#inqu_status1-0-fdCreateDepartment').val($('#fdCreateDepartment').val());
//	$('#inqu_status1-0-fdCreatorId').val($('#fdCreatorId').val());  
	
}; 

var ajax_callback1 = {
	onSuccess : function(eiInfo) {
		efwindow.hide(); 
		var grid = efgrid.getGridObject("ef_grid_d");
		grid.refresh(eiInfo);
	},
	onFail : function(eMsg) {}
};
button_query_onclick = function () 
{   	
	efgrid.submitInqu( "ef_grid_r", "ZM","ZMCG40","query");
}
button_update_onclick = function (){ 
	if (isSelected("ef_grid_r") == 0)return; 
	efgrid.submitForm( "ef_grid_r", "ZM","ZMCG40","update",true);
}
button_insert_onclick = function (){
	if (isSelected("ef_grid_r") == 0)return; 
	efgrid.submitForm( "ef_grid_r", "ZM","ZMCG40","insert",true);
//	var info = getSCZXEiInfos("ZMCG40","ef_grid_r");//ZMCN10 为EFFORM id，ef_grid_r为grid id（paintId）
//	if (null != info) { 
//		EiCommunicator.send("ZMCG40", "insert", info, validate_callback);
//	}

} 
button_resolve_onclick = function (){ 
	if (isSelected("ef_grid_r") == 0)return; 
	efgrid.submitForm( "ef_grid_r", "ZM","ZMCG40","resolve",true);
}
button_delete_onclick = function (){
	var grid=isSelected("ef_grid_r");
	if (grid == 0)return; 
	var rows=grid.getCheckedRows();
	for(var i=0;i<rows.length;i++)
	{
		if(grid.getCellValueByColumnName(rows[i],"fdStatus")!="0")
		{
			EFAlert("只能对跟踪中的记录进行删除！"); return;
		}
	}
	EFConfirm('你确认要删除吗?', '确认框', function(r) {
		if(r)efgrid.submitForm( "ef_grid_r", "ZM","ZMCG40","delete",true);
	});
	hideAndShowSubButtons(false);
}


efgrid_onRowClicked = function( grid_id, row_index ){
	if(grid_id == "ef_grid_r"){ 
		$('#ef_region_detail').show();//显示从表区域
		$('#ef_region_inqu1').show();//显示从表明细区域
		var grid = efgrid.getGridObject(grid_id);
		var fdChagneId=grid.getCellValueByColumnName(row_index,"fdKeyId");		
		var fdStatus=grid.getCellValueByColumnName(row_index,"fdStatus");
		var fdEditDate=grid.getCellValueByColumnName(row_index,"fdEditDate");
		//隐藏/显示从表按钮
		if(fdStatus!='0')
			hideAndShowSubButtons(false);
		else
			hideAndShowSubButtons(true);
		var info = new EiInfo();
		info.set("fdChagneId",fdChagneId); 
		info.set("fdStatus",fdStatus); 
		$('#fdChagneId').val(fdChagneId);
		$('#fdStatus').val(fdStatus);
		$('#inqu_status1-0-fdChagneId').val(fdChagneId);
		EiCommunicator.send("ZMCG4001", "query", info, ajax_callback);  
	}
	if(grid_id == "ef_grid_d"){ 
		var grid = efgrid.getGridObject(grid_id); 
		var selectedRow=grid.getRowData(row_index);
		for(var item in selectedRow){
			var colname=item;
			var colvalue=selectedRow[item];
			$('#ef_region_inqu1').find('#inqu_status1-0-'+colname).val(colvalue);
		} 
	}
}
var ajax_callback= {
	onSuccess: function(eiInfo) { 
		 efwindow.hide();
		 var grid = efgrid.getGridObject("ef_grid_d");
		 grid.refresh(eiInfo);
	},
	onFail:function(eMsg)
	{
		EFAlert("新增失败，原因："+eMsg); 
	}
}

var validate_callback={
		onSuccess:function(eiInfo){
			if(eiInfo.getStatus()==-1){
				EFAlert("操作失败，原因："+eiInfo.getMsg());
			}else{
				 efwindow.hide();
				 var grid = efgrid.getGridObject("ef_grid_r");
				 grid.refresh(eiInfo);
			}
		},
		onFail:function(eMsg)
		{
			EFAlert("操作失败，原因："+eMsg); 
		}
}
/********************************************************************************
 ***********************************从表操作**************************************** 
 ********************************************************************************/
button_insert1_onclick = function (){
	var ei_info=new EiInfo();
	ei_info.setByNodeObject(document.forms[0]); 
	if(ei_info.getBlock('inqu_status1').getRows(0)[0][2].length== 0){
		EFAlert("调度日期不能为空");
		return;
	}
	if(ei_info.getBlock('inqu_status1').getRows(0)[0][3].length== 0){
		EFAlert("生产班次不能为空");
		return;
	}
	if(ei_info.getBlock('inqu_status1').getRows(0)[0][4].length==0){
		EFAlert("接班人不能为空");
		return;
	}
	if(ei_info.getBlock('inqu_status1').getRows(0)[0][5].length==0){
		EFAlert("问题处理情况不能为空");
		return;
	}
	if(ei_info.getBlock('inqu_status1').getRows(0)[0][6].length==0){
		EFAlert("问题情况分析不能为空");
		return;
	}
	
	var info = getDetailbyBlockname("ef_region_inqu1","inqu_status1");
	if (null != info) { 
	//	EiCommunicator.send("ZMCG4001", "insert", info, ajax_callbackconfirm);
		info.set("efCurButtonEname","insert");
		EiCommunicator.send("ZMCG4001", "validate", info, validate1_callback);
	} 
	window.location.reload(); 
}

var validate1_callback={
		onSuccess:function(eiInfo){
			//EFAlert("ssss  +"+eiInfo.get("efCurButtonEname"));
			if(eiInfo.getStatus()==-1){
				EFAlert("操作失败，原因："+eiInfo.getMsg());
			}else{
/*				 efwindow.hide();
				 var grid = efgrid.getGridObject("ef_grid_r");
				 grid.refresh(eiInfo);*/
				var oper="insert";
				if(eiInfo.get("efCurButtonEname")=="UPDATE1"){
					oper="update";
				}
				efgrid.submitForm( "ef_grid_d", "ZM","ZMCG4001",oper,true);
			}
		},
		onFail:function(eMsg)
		{
			EFAlert("操作失败，原因："+eMsg); 
		}
}

button_update1_onclick = function (){ 
	var ei_info=new EiInfo();
	ei_info.setByNodeObject(document.forms[0]); 
	if(ei_info.getBlock('inqu_status1').getRows(0)[0][2].trim==""){
		EFAlert("调度日期不能为空");
		return;
	}
	if(ei_info.getBlock('inqu_status1').getRows(0)[0][3].trim==""){
		EFAlert("生产班次不能为空");
		return;
	}
	if(ei_info.getBlock('inqu_status1').getRows(0)[0][4].trim==""){
		EFAlert("接班人不能为空");
		return;
	}
	if(ei_info.getBlock('inqu_status1').getRows(0)[0][5].trim==""){
		EFAlert("问题处理情况不能为空");
		return;
	}
	if(ei_info.getBlock('inqu_status1').getRows(0)[0][6].trim==""){
		EFAlert("问题情况分析不能为空");
		return;
	}
	
	var info = getDetailbyBlockname("ef_region_inqu1","inqu_status1");
	if (null != info) {
		//EiCommunicator.send("ZMCG4001", "update", info, ajax_callbackconfirm);
		info.set("efCurButtonEname","UPDATE1");
		EiCommunicator.send("ZMCG4001", "validate", info, validate1_callback);
	} 
	window.location.reload(); 
}
button_delete1_onclick = function (){
	var grid=isSelected("ef_grid_d");
	if (grid == 0)return;  
	EFConfirm('你确认要删除吗?', '确认框', function(r) {
		if(r){
			efgrid.submitForm( "ef_grid_d", "ZM","ZMCG4001","delete",true);
		}
	}); 
}  
var ajax_callbackconfirm = {
	onSuccess : function(eiInfo) {
		efwindow.hide(); 
		var grid = efgrid.getGridObject("ef_grid_d");
		grid.refresh(eiInfo);
	}, 
	onFail:function(eMsg)
	{
		alert("确认失败，原因："+eMsg);
	}
}


var hideAndShowSubButtons=function(status)
{
	if(!status)
	{
		efbutton.setButtonStatus("insert1", false);
		efbutton.setButtonStatus("update1", false);
		efbutton.setButtonStatus("delete1", false);
	}else
	{
		efbutton.setButtonStatus("insert1", true);
		efbutton.setButtonStatus("update1", true);
		efbutton.setButtonStatus("delete1", true);
	}
}
//efgrid_afterAddNewRow = function(grid_id){ 
//	var grid = efgrid.getGridObject(grid_id);
//	var rows = grid.getCheckedRows(); 
//	if(grid_id=="ef_grid_r")
//	{
//		var fdCreateUser=$('#fdCreateUser').val();
//		var fdCreateDepartment=$('#fdCreateDepartment').val();
//		var fdCreateUserId=$('#fdCreateUserId').val();
//		var fdCreateDepartmentId=$('#fdCreateDepartmentId').val(); 
//	   
//		for(var i = 0 ; i < rows.length;i++){
//			grid.setCellValue(rows[i],1,fdCreateUserId,TYPE_DATA); 
//			grid.setCellValue(rows[i],2,fdCreateUser,TYPE_DATA);
//			grid.setCellValue(rows[i],3,fdCreateDepartmentId,TYPE_DATA);
////			grid.setCellValue(rows[i],3,fdCreateDepartment,TYPE_DATA);
//		}
//	}
//}
//efgrid_onCellDisplayReady = function( div_node_html, row_index, col_index, col_value_c, display_value, grid_id )
//{
//  //多Grid时的检验
//  if (grid_id != "ef_grid_r") return;
//  var grid = efgrid.getGridObject( grid_id );
//  if(!grid.getColumn(col_index, TYPE_DATA)) return;
//  var columnEname = grid.getColumn(col_index, TYPE_DATA).getEname(); 
//  switch (columnEname) { 
//     case "operation":
//         var html = "<div align=center><a target='_blank' href='#'>上传附件</a></div>";
//         return html;    
//  }
//}

/**----------------------------从这里往下的方法都是附件操作相关方法------------------
 */
button_upload_onclick=function(){
	var grid = efgrid.getGridObject("ef_grid_r");
	var row_index=grid.getCurrentRowIndex();
	if(row_index<0){
		EFAlert("请先点击一下选中项目信息后上传！");
		return;
	}
	var docId=grid.getCellValueByColumnName(row_index,"fdDocId");
	if(!isAvailable(docId)) {
		EFAlert("未指定文档号！", "系统警告");
		return false;
	}
	var url = "DispatchAction.do?efFormEname=EUAF3501";
		url = url + "&inqu_status-0-code=zm.cg";
	
	if(grid.getCellValueByColumnName(row_index,"fdStatus")!='0')
	{
		url = url + "&editFlag=0";
	}else{
		url = url + "&editFlag=1";
	}
	url = url + "&inqu_status-0-docId="+docId+"&time=" + new Date().getTime();
	
	EFColorbox({href:url,title:"附件管理",width:"80%", height:"80%", iframe:true});
}  